// 用于封装本地存储
function setItem(key, value) {
  if (typeof value === 'object') {
    value = JSON.stringify(value)
  }
  localStorage.setItem(key, value)
}
function getItem(key) {
  const data = localStorage.getItem(key)
  try {
    // 如果不能转化成功就会进入catch
    return JSON.parse(data)
  } catch (error) {
    return data
  }
}
function removeItem(key) {
  localStorage.removeItem(key)
}
export { setItem, getItem, removeItem }
